﻿using BCCommon.Enums;
using BCData.WeChatComponent.WeChatMessageRecord;
using BCEntity.WeChatComponent.WeChatMessageRecord;
using System;
using System.Collections.Generic;
using System.Text;
using WeChatSDK.WeChatDto.Conversation.ReceivingMessage;
using WeChatSDK.WeChatDto.Conversation.ReceivingMessage.EventMessage;

namespace BCService.WeChatComponent.WeChatHandleService.EventMessageService.ViewEventMessageService
{
    /// <summary>
    /// 点击菜单跳转链接时的事件处理
    /// </summary>
    public class ViewEventMessageService : IWeChatMessageHandle
    {
        private readonly IWeChatMessageRecordData weChatMessageRecordData;

        public ViewEventMessageService(IWeChatMessageRecordData weChatMessageRecordData)
        {
            this.weChatMessageRecordData = weChatMessageRecordData;
        }

        public string HandleMessage(ReceivingMessageDto message)
        {
            ViewEventMessageDto viewEventMessageDto = (ViewEventMessageDto)message;
            WeChatMessageRecordEntity weChatMessageRecordEntity = this.RecordReceivingMessage(viewEventMessageDto);
            //TODO:这里可以增加事件处理（根据具体业务而定）
            string response = "success";
            return response;
        }

        private WeChatMessageRecordEntity RecordReceivingMessage(ViewEventMessageDto viewEventMessageDto)
        {
            WeChatMessageRecordEntity entity = new WeChatMessageRecordEntity()
            {
                ToUserName = viewEventMessageDto.ToUserName,
                FromUserName = viewEventMessageDto.FromUserName,
                MessageType = WeChatMessageType.Event,
                MessageId = viewEventMessageDto.MsgId,
                EventName = viewEventMessageDto.Event,
                EventKey = viewEventMessageDto.EventKey,
                Title = "用户点击菜单跳转事件",
                IsReply = false
            };
            return this.weChatMessageRecordData.Add(entity);
        }
    }
}
